#include<bits/stdc++.h>
using namespace std;
#define OK 1
#define ERROR 0
typedef int Status;
typedef struct LNode{
	int data;
	LNode *next;	
}LNode, *LinkList; 
Status Init(LinkList &L)
{
	L = new LNode;
	if(!L) return ERROR;
	L->next = NULL;
	return OK;
}
Status Create(LinkList &L, int n)
{
	LNode *t = L;
	for(int i = 0; i < n; i ++)
	{
		LNode *p = new LNode;
		if(!p) return ERROR;
		cin >> p->data;
		p->next = t->next;
		t->next = p;
		t = p;
	}
	return OK;
}
int Pattern(LinkList A, LinkList B) // 判断序列B是否是序列A的连续子序列
{
	/*******************Begin*****************/
    if(B->next == NULL) return 1;
	
	LNode *pa = A, *pb = B;
	while(pa)
	{
		while(pb)
		{
			if(pa->data != pb->data) break;
			pa = pa->next;
			pb = pb->next;
			if(!pb) return 1;
		}
		pa = pa->next;
		pb = B->next; 
	} 
	return 0;
    /*******************End*******************/
}
void Show(LinkList L)
{
	LNode *p = L->next;
	while(p)
	{
		cout << p->data << ' ';
		p = p->next;
	}
	cout << endl;
}
int main()
{
	LinkList L1, L2;
	Init(L1);
	Init(L2);

	
	int n1, n2;
	cin >> n1 >> n2;
	
	Create(L1, n1);
	Create(L2, n2);
	
	int flag = Pattern(L1->next, L2->next);
	 
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}